/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.helper_classes;

import cse308.entities.Courseoutcomesurveyresults;
import cse308.entities.Courseoffering;
import cse308.entities.Courseoutcomedirectassessment;
import cse308.entities.Assignment;
import cse308.GUIUtilityClass;
import cse308.General;
import cse308.GeneralEntity;
import cse308.entities.CourseofferingPK;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.http.Part;

/**
 *
 * @author Aaron
 */
public class CourseofferingClass implements GeneralTest {

    private boolean isAltCoursecoordinator = false;
    private boolean isCourseCoordinator = false;
    private boolean isInstructor = false;
    private boolean notCIC = false;
    private String course;
    private int section;
    private String semester;
    private String instructor;
    private String coursecoordinator;
    private String altcoursecoordinator;
    private File syllabusFile;
    private String syllabusLink;
    private byte[] syllabus;
    private Part syllabusPart;
    private File scheduleOfLecturesFile;
    private String scheduleLink;
    private byte[] schedule;
    private Part schedulePart;
    private File lectureNotesFile;
    private String lectureLink;
    private Part lecturePart;
    private byte[] lectureNotes;
    private Map<String, Object> assignments;
    private String courseOutcomeAttainmentTarget;
    private Map<String, Object> courseOutcomeDirectAssessments;
    private Map<String, Object> courseOutcomeSurveyResults;
    private File endOfSemesterReportFile;
    private String endLink;
    private byte[] endOfSemesterReport;
    private Part endOfSemesterReportPart;
    private File courseCoordinatorReportFile;
    private String courseLink;
    private byte[] courseCoordinatorReport;
    private Part courseCoordinatorReportPart;
    private File CICReportFile;
    private String CICLink;
    private byte[] cICReport;
    private Part cICReportPart;
    private List<String> allAssignments = new ArrayList();
    private List<String> ownAssignments = new ArrayList();
    private Map<String, General> assignmentMap = new HashMap();
    private List<String> allCourseOutcomeDirectAssessments = new ArrayList();
    private List<String> ownCourseOutcomeDirectAssessments = new ArrayList();
    private Map<String, General> courseOutcomeDirectAssessmentsMap = new HashMap();
    private List<String> allCourseOutcomeSurveyResults = new ArrayList();
    private List<String> ownCourseOutcomeSurveyResults = new ArrayList();
    private Map<String, General> courseOutcomeSurveyResultsMap = new HashMap();
    private final static Logger LOG = Logger.getLogger(GUIUtilityClass.class.getName());

    public CourseofferingClass(Courseoffering entity) {

        this.assignments = new HashMap();
        this.courseOutcomeDirectAssessments = new HashMap();
        this.courseOutcomeSurveyResults = new HashMap();
        int id = GUIUtilityClass.courseOfferingIterator;
        try {
            this.syllabusFile = GUIUtilityClass.convertToFile(entity.getSyllabus(), "syllabus" + id + ".txt");
            this.scheduleOfLecturesFile = GUIUtilityClass.convertToFile(entity.getSchedule(), "schedule" + id + ".txt");
            this.lectureNotesFile = GUIUtilityClass.convertToFile(entity.getLectureNotes(), "lecture_notes" + id + ".txt");
            this.endOfSemesterReportFile = GUIUtilityClass.convertToFile(entity.getEndOfSemesterReport(), "end_of_semester_report" + id + ".txt");
            this.courseCoordinatorReportFile = GUIUtilityClass.convertToFile(entity.getCourseCoordinatorReport(), "course_coordinator_report" + id + ".txt");
            this.CICReportFile = GUIUtilityClass.convertToFile(entity.getCICReport(), "cic_report" + id + ".txt");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(CourseofferingClass.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CourseofferingClass.class.getName()).log(Level.SEVERE, null, ex);
        }

        this.course = entity.getCourseofferingPK().getCourse();
        this.section = entity.getCourseofferingPK().getSection();
        this.semester = entity.getCourseofferingPK().getSemester();
        this.instructor = entity.getInstructor();
        //this.courseCoordinator = entity.getCourseCoordinator();
        this.syllabusLink = "Syllabus";
        this.scheduleLink = "Schedule";
        this.lectureLink = "Lecture Notes";
        this.courseOutcomeAttainmentTarget = entity.getCourseOutcomeAttainmentTarget();
        this.endLink = "End of Semester Report";
        this.courseLink = "Course Coordinator Report";
        this.CICLink = "CIC Report";
        for (Assignment a : entity.getAssignmentCollection()) {
            assignments.put(a.getName(), a.getName());
        }
        for (Courseoutcomedirectassessment coda : entity.getCourseoutcomedirectassessmentCollection()) {
            this.courseOutcomeDirectAssessments.put(coda.getIdentifier2()  , coda.getIdentifier2());
        }
        for (Courseoutcomesurveyresults cosr : entity.getCourseoutcomesurveyresultsCollection()) {
            String putInMap = cosr.getCourseoffering().getCourseofferingPK().getCourse() + cosr.getAverageRatingAttainment();
            this.courseOutcomeSurveyResults.put(putInMap, putInMap);
        }
        id++;
    }

    public boolean isIsAltCoursecoordinator() {
        return isAltCoursecoordinator;
    }

    public void setIsAltCoursecoordinator(boolean isAltCoursecoordinator) {
        this.isAltCoursecoordinator = isAltCoursecoordinator;
    }

    
    public boolean isIsCourseCoordinator() {
        return isCourseCoordinator;
    }

    public void setIsCourseCoordinator(boolean isCourseCoordinator) {
        this.isCourseCoordinator = isCourseCoordinator;
    }

    
    public boolean isIsInstructor() {
        return isInstructor;
    }

    public void setIsInstructor(boolean isInstructor) {
        this.isInstructor = isInstructor;
    }

    
    public boolean isNotCIC() {
        return notCIC;
    }

    public void setNotCIC(boolean notCIC) {
        this.notCIC = notCIC;
    }

    
    public String getCoursecoordinator() {
        return coursecoordinator;
    }

    public void setCoursecoordinator(String coursecoordinator) {
        this.coursecoordinator = coursecoordinator;
    }

    public String getAltcoursecoordinator() {
        return altcoursecoordinator;
    }

    public void setAltcoursecoordinator(String altcoursecoordinator) {
        this.altcoursecoordinator = altcoursecoordinator;
    }

    public String getCourse() {
        return course;
    }

    public void setCourse(String course) {
        this.course = course;
    }

    public int getSection() {
        return section;
    }

    public void setSection(int section) {
        this.section = section;
    }

    public String getSemester() {
        return semester;
    }

    public void setSemester(String semester) {
        this.semester = semester;
    }

    public String getInstructor() {
        return instructor;
    }

    public void setInstructor(String instructor) {
        this.instructor = instructor;
    }

    public String getSyllabusLink() {
        return syllabusLink;
    }

    public void setSyllabusLink(String syllabusLink) {
        this.syllabusLink = syllabusLink;
    }

    public String getScheduleLink() {
        return scheduleLink;
    }

    public void setScheduleLink(String scheduleLink) {
        this.scheduleLink = scheduleLink;
    }

    public String getLectureLink() {
        return lectureLink;
    }

    public void setLectureLink(String lectureLink) {
        this.lectureLink = lectureLink;
    }

    public Map<String, Object> getAssignments() {
        return assignments;
    }

    public void setAssignments(Map<String, Object> assignments) {
        this.assignments = assignments;
    }

    public String getCourseOutcomeAttainmentTarget() {
        return courseOutcomeAttainmentTarget;
    }

    public void setCourseOutcomeAttainmentTarget(String courseOutcomeAttinmentTarget) {
        this.courseOutcomeAttainmentTarget = courseOutcomeAttinmentTarget;
    }

    public Map<String, Object> getCourseOutcomeDirectAssessments() {
        return courseOutcomeDirectAssessments;
    }

    public void setCourseOutcomeDirectAssessments(Map<String, Object> courseOutcomeDirectAssessments) {
        this.courseOutcomeDirectAssessments = courseOutcomeDirectAssessments;
    }

    public Map<String, Object> getCourseOutcomeSurveyResults() {
        return courseOutcomeSurveyResults;
    }

    public void setCourseOutcomeSurveyResults(Map<String, Object> courseOutcomeSurveyResults) {
        this.courseOutcomeSurveyResults = courseOutcomeSurveyResults;
    }

    public String getEndLink() {
        return endLink;
    }

    public void setEndLink(String endLink) {
        this.endLink = endLink;
    }

    public String getCourseLink() {
        return courseLink;
    }

    public void setCourseLink(String courseLink) {
        this.courseLink = courseLink;
    }

    public String getCICLink() {
        return CICLink;
    }

    public void setCICLink(String CICLink) {
        this.CICLink = CICLink;
    }

    public List<String> getAllAssignments() {
        return allAssignments;
    }

    public void setAllAssignments(List<String> allAssignments) {
        this.allAssignments = allAssignments;
    }

    public List<String> getOwnAssignments() {
        return ownAssignments;
    }

    public void setOwnAssignments(List<String> ownAssignments) {
        this.ownAssignments = ownAssignments;
    }

    public Map<String, General> getAssignmentMap() {
        return assignmentMap;
    }

    public void setAssignmentMap(Map<String, General> assignmentMap) {
        this.assignmentMap = assignmentMap;
    }

    public List<String> getAllCourseOutcomeDirectAssessments() {
        return allCourseOutcomeDirectAssessments;
    }

    public void setAllCourseOutcomeDirectAssessments(List<String> allCourseOutcomeDirectAssessments) {
        this.allCourseOutcomeDirectAssessments = allCourseOutcomeDirectAssessments;
    }

    public List<String> getOwnCourseOutcomeDirectAssessments() {
        return ownCourseOutcomeDirectAssessments;
    }

    public void setOwnCourseOutcomeDirectAssessments(List<String> ownCourseOutcomeDirectAssessments) {
        this.ownCourseOutcomeDirectAssessments = ownCourseOutcomeDirectAssessments;
    }

    public Map<String, General> getCourseOutcomeDirectAssessmentsMap() {
        return courseOutcomeDirectAssessmentsMap;
    }

    public void setCourseOutcomeDirectAssessmentsMap(Map<String, General> courseOutcomeDirectAssessmentsMap) {
        this.courseOutcomeDirectAssessmentsMap = courseOutcomeDirectAssessmentsMap;
    }

    public List<String> getAllCourseOutcomeSurveyResults() {
        return allCourseOutcomeSurveyResults;
    }

    public void setAllCourseOutcomeSurveyResults(List<String> allCourseOutcomeSurveyResults) {
        this.allCourseOutcomeSurveyResults = allCourseOutcomeSurveyResults;
    }

    public List<String> getOwnCourseOutcomeSurveyResults() {
        return ownCourseOutcomeSurveyResults;
    }

    public void setOwnCourseOutcomeSurveyResults(List<String> ownCourseOutcomeSurveyResults) {
        this.ownCourseOutcomeSurveyResults = ownCourseOutcomeSurveyResults;
    }

    public Map<String, General> getCourseOutcomeSurveyResultsMap() {
        return courseOutcomeSurveyResultsMap;
    }

    public void setCourseOutcomeSurveyResultsMap(Map<String, General> courseOutcomeSurveyResultsMap) {
        this.courseOutcomeSurveyResultsMap = courseOutcomeSurveyResultsMap;
    }

    @Override
    public ArrayList<Map<String, General>> getMap() {
        ArrayList<Map<String, General>> maps = new ArrayList();
        maps.add(this.assignmentMap);
        maps.add(this.courseOutcomeDirectAssessmentsMap);
        maps.add(this.courseOutcomeSurveyResultsMap);
        return maps;
    }

    @Override
    public ArrayList<List<String>> getList() {
        ArrayList<List<String>> lists = new ArrayList();
        lists.add(this.ownAssignments);
        lists.add(this.ownCourseOutcomeDirectAssessments);
        lists.add(this.ownCourseOutcomeSurveyResults);
        return lists;
    }

    //@Override
    public void updateRelationship(GeneralEntity ge1) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("CSE_308_ABETPU");
        EntityManager em = emf.createEntityManager();
        CourseofferingPK primaryKey = new CourseofferingPK(this.course, this.section, this.semester);
        return em.find(Courseoffering.class, primaryKey);
    }

    @Override
    public String getIdentifier2() {
        return this.course;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        if (entity instanceof Courseoffering) {
            Courseoffering co = (Courseoffering) entity;
            CourseofferingPK coPK = co.getCourseofferingPK();
            if (coPK.getCourse().equals(this.course) && coPK.getSection() == this.section && coPK.getSemester().equals(this.semester)) {
                return true;
            }
        }
        return false;
    }

    public File getSyllabusFile() {
        return syllabusFile;
    }

    public void setSyllabusFile(File syllabusFile) {
        this.syllabusFile = syllabusFile;
    }

    public File getScheduleOfLecturesFile() {
        return scheduleOfLecturesFile;
    }

    public void setScheduleOfLecturesFile(File scheduleOfLecturesFile) {
        this.scheduleOfLecturesFile = scheduleOfLecturesFile;
    }

    public File getLectureNotesFile() {
        return lectureNotesFile;
    }

    public void setLectureNotesFile(File lectureNotesFile) {
        this.lectureNotesFile = lectureNotesFile;
    }

    public File getEndOfSemesterReportFile() {
        return endOfSemesterReportFile;
    }

    public void setEndOfSemesterReportFile(File endOfSemesterReportFile) {
        this.endOfSemesterReportFile = endOfSemesterReportFile;
    }

    public File getCourseCoordinatorReportFile() {
        return courseCoordinatorReportFile;
    }

    public void setCourseCoordinatorReportFile(File courseCoordinatorReportFile) {
        this.courseCoordinatorReportFile = courseCoordinatorReportFile;
    }

    public File getCICReportFile() {
        return CICReportFile;
    }

    public void setCICReportFile(File CICReportFile) {
        this.CICReportFile = CICReportFile;
    }

    public byte[] getSyllabus() {
        return syllabus;
    }

    public void setSyllabus(byte[] syllabus) {
        this.syllabus = syllabus;
    }

    public byte[] getScheduleOfLectures() {
        return schedule;
    }

    public void setScheduleOfLectures(byte[] scheduleOfLectures) {
        this.schedule = scheduleOfLectures;
    }

    public byte[] getLectureNotes() {
        return lectureNotes;
    }

    public void setLectureNotes(byte[] lectureNotes) {
        this.lectureNotes = lectureNotes;
    }

    public byte[] getEndOfSemesterReport() {
        return endOfSemesterReport;
    }

    public void setEndOfSemesterReport(byte[] endOfSemesterReport) {
        this.endOfSemesterReport = endOfSemesterReport;
    }

    public byte[] getCourseCoordinatorReport() {
        return courseCoordinatorReport;
    }

    public void setCourseCoordinatorReport(byte[] courseCoordinatorReport) {
        this.courseCoordinatorReport = courseCoordinatorReport;
    }

    public byte[] getCICReport() {
        return cICReport;
    }

    public void setCICReport(byte[] CICReport) {
        this.cICReport = CICReport;
    }

    public Part getSyllabusPart() {
        return syllabusPart;
    }

    public void setSyllabusPart(Part syllabusPart) {
        this.syllabusPart = syllabusPart;
        this.syllabus = GUIUtilityClass.convertToBytesByPart(syllabusPart);
    }

    public byte[] getSchedule() {
        return schedule;
    }

    public void setSchedule(byte[] schedule) {
        this.schedule = schedule;
    }

    public Part getSchedulePart() {
        return schedulePart;
    }

    public void setSchedulePart(Part schedulePart) {
        this.schedulePart = schedulePart;
        this.schedule = GUIUtilityClass.convertToBytesByPart(schedulePart);
    }

    public Part getLecturePart() {
        return lecturePart;
    }

    public void setLecturePart(Part lecturePart) {
        this.lecturePart = lecturePart;
        this.lectureNotes = GUIUtilityClass.convertToBytesByPart(lecturePart);
    }

    public Part getEndOfSemesterReportPart() {
        return endOfSemesterReportPart;
    }

    public void setEndOfSemesterReportPart(Part endOfSemesterReportPart) {
        this.endOfSemesterReportPart = endOfSemesterReportPart;
        this.endOfSemesterReport = GUIUtilityClass.convertToBytesByPart(endOfSemesterReportPart);
    }

    public Part getCourseCoordinatorReportPart() {
        return courseCoordinatorReportPart;
    }

    public void setCourseCoordinatorReportPart(Part courseCoordinatorReportPart) {
        this.courseCoordinatorReportPart = courseCoordinatorReportPart;
        this.courseCoordinatorReport = GUIUtilityClass.convertToBytesByPart(courseCoordinatorReportPart);
    }

    public byte[] getcICReport() {
        return cICReport;
    }

    public void setcICReport(byte[] cICReport) {
        this.cICReport = cICReport;
    }

    public Part getcICReportPart() {
        return cICReportPart;
    }

    public void setcICReportPart(Part cICReportPart) {
        this.cICReportPart = cICReportPart;
        this.cICReport = GUIUtilityClass.convertToBytesByPart(cICReportPart);
    }
}
